package com.unionftech.crm_android;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.unionftech.common.utils.LogUtils;
import com.unionftech.crm_android.ui.UFSplashActivity;

import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;

public class LocaleChangeReceiver extends BroadcastReceiver {
    @SuppressLint("CheckResult")
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
            // 系统语言发生变化，处理逻辑
            LogUtils.d("LocaleChangeReceiver", "System language changed");
            // 例如：重启应用或更新 UI
            Intent newIntent = new Intent(context, UFSplashActivity.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(newIntent);
            Observable.timer(300, TimeUnit.MILLISECONDS)
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .subscribe(aLong -> android.os.Process.killProcess(android.os.Process.myPid()));

        }
    }
}